package com.gongpingjialoan.utility;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by chuang on 2016/8/5.
 */
public class TimeUtils {

    public final static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String timeChineseFormat(String time){
        if(time == null)return "";
        SimpleDateFormat sdf0 = new SimpleDateFormat(TIME_FORMAT);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date();
        try {
            date = sdf0.parse(time);
        } catch (ParseException e) {
            Utils.LogD("TimeUtils timeChineseFormat : "+ e.getMessage());
        }
        return sdf.format(date);
    }

    public static String timeFormat(String time){
        if(time == null)return "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf0 = new SimpleDateFormat(TIME_FORMAT);
        Date date = new Date();
        try {
            date = sdf0.parse(time);
        } catch (ParseException e) {
            Utils.LogD("TimeUtils timeFormat : "+ e.getMessage());
        }
        return sdf.format(date);
    }

    public static String timeMonthDayFormat(String time){
        if(time == null)return "";
        SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
        SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date();
        try {
            date = sdf0.parse(time);
        } catch (ParseException e) {
            Utils.LogD("TimeUtils timeMonthDayFormat : "+ e.getMessage());
        }
        return sdf.format(date);
    }

    public static String timeMonthDayHourFormat(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH时");
        return sdf.format(date);
    }


    public static String timeMonthHourMinFormat(long time){
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        Date date = new Date(time);
        return sdf.format(date);
    }

    public static String timeYearMonthDayFormat(long time){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(time);
        return sdf.format(date);
    }
    /*将字符串转为时间戳*/
    public static long getStringToDate(String time) {
        SimpleDateFormat sdf = null;
        sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        try{
            date = sdf.parse(time);
        } catch(ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date.getTime();
    }
}
